﻿// ===============================================================================
// NameRule.cs
// EOS Web Framework
// ===============================================================================
// Copyright (c) EOS Development Group. All rights reserved.
// ===============================================================================

namespace EOS.Framework.Rules
{
    using System;

    /// <summary>
    /// Rule for simple names with numbers.a
    /// </summary>
    public class NameRule : RegexRule
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NameRule"/> class
        /// with a description
        /// </summary>
        /// <param name="brokenDescription">A description of the rule that will be shown
        /// if the rule is broken. Cannot be null or empty or contains only whitespaces.</param>
        /// <exception cref="ArgumentNullException"><paramref name="brokenDescription"/> is
        /// null (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="brokenDescription"/> is a string
        /// of length 0 or contains only blanks.</exception>
        public NameRule(string description)
            : this(description, false)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="NameRule"/> class
        /// with a description and a flag, indicating, if the value can be empty.
        /// </summary>
        /// <param name="canBeEmpty">if set to <c>true</c> the value can be empty.</param>
        /// <param name="brokenDescription">A description of the rule that will be shown
        /// if the rule is broken. Cannot be null or empty or contains only whitespaces.</param>
        /// <exception cref="ArgumentNullException"><paramref name="brokenDescription"/> is
        /// null (Nothing in Visual Basic).</exception>
        /// <exception cref="ArgumentException"><paramref name="brokenDescription"/> is a string
        /// of length 0 or contains only blanks.</exception>
        public NameRule(string brokenDescription, bool canBeEmpty)
            : base(brokenDescription,
            "^([A-ZÄÖÜ]{1}[a-zäöüß]+)((\\s)*(\\s|\\-|\\/)(\\s)*[A-ZÄÖÜa-zäöüß\\(\\)]+)*$",
            canBeEmpty)
        { 
        }
    }
}